package com.jbh.yxjdemobykontlin

import android.content.Context
import android.graphics.Bitmap
import android.util.AttributeSet
import android.widget.ImageView
import android.widget.LinearLayout

class MyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
    LinearLayout(context, attrs, defStyleAttr) {

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context) : this(context, null)

    init {
        orientation = VERTICAL
        addIcon()
    }


    private var img: ImageView? = null
    private fun addIcon() {
        img = ImageView(context).apply {
            adjustViewBounds = true
            setBackgroundResource(R.mipmap.ic_launcher)
        }
        addView(img, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))
    }


    fun showImg(b:Bitmap){
        img?.setImageBitmap(b)
    }


}